package com.example.shushiyunsst.util.flutter_bridgt;

import android.util.Log;

import org.jetbrains.annotations.NotNull;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;

public class EventChannelPlugin implements EventChannel.StreamHandler {
    private EventChannel.EventSink eventSink;
    
    @NotNull
   public static EventChannelPlugin registerWith(BinaryMessenger messenger,String name) {
        EventChannelPlugin plugin = new EventChannelPlugin();
        new EventChannel(messenger, name).setStreamHandler(plugin);
        return plugin;
    }

   public void send(Object params) {
        if (eventSink != null) {
            eventSink.success(params);
        }
    }

    @Override
    public void onListen(Object args, EventChannel.EventSink eventSink) {
        Log.d("onListen", "onListen: ");
        this.eventSink = eventSink;
    }

    @Override
    public void onCancel(Object o) {
        eventSink = null;
    }
}
